package video.interfaces.controller;

import video.domain.model.Video;
import video.application.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api/videos")
public class VideoController {

    @Autowired
    private VideoService service;

    // 新增视频
    @PostMapping
    public Video create(@RequestBody Video video) {
        return service.create(video);
    }

    // 全部视频（管理员端）
    @GetMapping
    public List<Video> listAll() {
        return service.listAll();
    }

    // 单个视频
    @GetMapping("/{id}")
    public Optional<Video> get(@PathVariable Long id) {
        return service.get(id);
    }

    // 修改视频
    @PutMapping("/{id}")
    public Video update(@PathVariable Long id, @RequestBody Video video) {
        return service.update(id, video);
    }

    // 删除视频
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id) {
        service.delete(id);
    }

    // 用户端公开视频
    @GetMapping("/public")
    public List<Video> listVisible() {
        return service.listVisible();
    }
}
